from gpiozero import  DigitalOutputDevice
from gpiozero.pins.pigpio import PiGPIOFactory

class Laser:
    ON=0
    OFF=1
   
    def __init__(self,spin):
        self.laser= DigitalOutputDevice(pin=spin,pin_factory=PiGPIOFactory())
        self.DICT_CMD_ACTION = {Laser.ON: self.laser.on,
                                Laser.OFF: self.laser.off,
                                }        

    def action(self, cmd_to_laser):
        self.DICT_CMD_ACTION[cmd_to_laser]()

      
if __name__ == '__main__': 
    import time
    laser = Laser(12)  # singal
    laser.action(Laser.ON)
    time.sleep(2)
    laser.action(Laser.OFF)
    time.sleep(2)
    laser.action(Laser.ON)
    